﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UIWindows.Domains;
using UIWindows.Commands;
using System.Windows.Controls;
using UIWindows.Views.Logs;
using UIWindows.ViewModels.Logs;
using UIWindows.Tools.Helper;
using System.IO;
using UIWindows.GlobalStatics;

namespace UIWindows.ViewModels
{
    public class LogSystemViewModel : ViewModelBase
    {
        private UserControl _viewContent;
        /// <summary>
        /// 视图
        /// </summary>
        public UserControl ViewContent
        {
            get { return _viewContent; }
            set { SetProperty(ref _viewContent, value); }
        }

        private List<UserControl> _userControls;
        private GlobalStatics.LogStatic _logStatic;

        public LogSystemViewModel(GlobalStatics.LogStatic logStatic, GlobalStatics.UserConfigStatic userConfig, ParameterStatic parameter, TemporaryStatic temporary)
        {
            _userControls = new List<UserControl>() { 
                new HistoricalEventLog() { DataContext = new HistoricalEventLogVModel(logStatic) },
                new HistoryLogRun(){ DataContext = new HistoryLogRunVModel(logStatic) },
                new HistoryLogOperation() { DataContext = new HistoryLogOperationVModel(logStatic, userConfig) },
                new HistoryLogMES(){ DataContext = new HistoryLogMESVModel(logStatic, parameter, temporary) },
            };
            ViewContent = _userControls[0];
            DialogLogHelper.Init();
            _logStatic = logStatic;
        }

        public DelegateCommand<RadioButton> ViewToggle => new DelegateCommand<RadioButton>(sender =>
        {
            if (sender == null){ return; }
            switch (sender.Content.ToString())
            {
                case "实时日志":
                    ViewContent = _userControls[0];
                    break;
                case "运行历史":
                    ViewContent = _userControls[1];
                    break;
                case "操作历史":
                    ViewContent = _userControls[2];
                    break;
                case "MES历史":
                    ViewContent = _userControls[3];
                    break;
            }
        });
    }
}
